{extend name="public:base"}
{block name='css'}
{/block}

{block name='body'}
<div class="view view-main white-navbar white-toolbar">
    <div data-name="home" class="page">

        <div class="navbar">
            <div class="navbar-inner">
                <div class="left"><a href="{$back}" class="external"><i class="iconfont icon-fanhui"></i></a></div>
                <div class="center"><span>详情</span></div>
                <div class="right"></div>
            </div>
        </div>

        <div class="page-content infinite-scroll-content">

            <div class="me-tongzhi" >
                <div class="js-ul">
                    <div class="li">
                        <div class="t">
                            <span>{:date('Y-m-d H:i:s',$info.time)}</span>
                        </div>
                        <div class="m">
                            <p class="p1">{$info.title}</p>
                            <p class="p2">{$info.content}</p>
                        </div>
                    </div>
                </div>
                
            </div>

        </div>


    </div>
</div>
{/block}

{block name="js"}
<script type="text/javascript">
    function showThis(self, state) {
        $('.me-msg-top .li a').removeClass('on');
        $(self).children().addClass('on');
        if (state == 1) {
            $('.me-tongzhi').show();
            $('.me-msg-list').hide();
        } else {
            $('.me-tongzhi').hide();
            $('.me-msg-list').show();
        }
    }
    function getMsgList() {
        var obj = $('.me-msg-list ul');
        var total = obj.find('li').length;
        getList(obj, total, 1);
    }
    function getTzList() {
        var obj = $('.me-tongzhi .js-ul');
        var total = obj.find('.li').length;
        getList(obj, total, 0);
    }
    function getList(obj, total, state) {
        if (total % 10 != 0) {
            return false;
        }
        if (obj.parent().find('.loading').is(':visible') || obj.parent().find('.no-more').is(':visible') || obj.parent().find('.no-data').is(':visible')) {
            return false;
        }
        obj.parent().find('.loading').show();

        var p = total / 10;
        $.post("{:url('getMsgList')}", {page:p+1,state:state}, function(data){
            var str = '';
            obj.parent().find('.loading').hide();
            if (data.data.data.length > 0) {
                $.each(data.data.data, function(i,n){
                    if (state == 0) {
                        str += '<div class="li">\n' +
                            '    <div class="t">\n' +
                            '        <span>'+n.add_time+'</span>\n' +
                            '    </div>\n' +
                            '    <div class="m">\n' +
                            (n.is_read ? '' : '        <span class="badge color-red"></span>\n') +
                            '        <p class="p1">'+n.title+'</p>\n' +
                            '        <p class="p2">'+n.content+'</p>\n' +
                            '    </div>\n' +
                            '</div>';
                    } else {
                        str += '<li>\n' +
                            '    <div class="item-content">\n' +
                            '        <div class="item-inner">\n' +
                            '            <p class="p1">'+(n.is_read ? '' : '<span class="badge color-red"></span>')+''+n.content+'</p>\n' +
                            '            <p class="p2">'+n.add_time+'</p>\n' +
                            '        </div>\n' +
                            '    </div>\n' +
                            '</li>';
                    }
                });
                if (data.data.data.length < 10) {
                    obj.parent().find('.no-more').show();
                }
                $(str).appendTo(obj);
            } else {
                if (total > 0) {
                    obj.parent().find('.no-more').show();
                } else {
                    obj.parent().find('.no-data').show();
                }
            }
        }, 'json');
    }
    $(function(){
        getTzList();
        getMsgList();
    });
    //触发无限滚动
    $$('.infinite-scroll-content').on('infinite', function () {
        if ($('.me-tongzhi').is(':visible')) {
            getTzList();
        } else {
            getMsgList();
        }
    });
</script>
{/block}